package com.lmiot.xyclick.Util;

import android.content.Context;
import android.content.pm.PackageInfo;
import com.lmiot.xyclick.Bean.AppBean;
import com.lkx.liandianqinew.R;
import java.util.ArrayList;
import java.util.List;

public class ApplicationInfoUtil {
    public static final int DEFAULT = 0;
    public static final int NONSYSTEM_APP = 2;
    public static final int SYSTEM_APP = 1;

    public static ArrayList<AppBean> getAllApp(Context context) {
        ArrayList<AppBean> arrayList = new ArrayList<>();
        List<PackageInfo> installedPackages = context.getPackageManager().getInstalledPackages(0);
        for (int i = 0; i < installedPackages.size(); i++) {
            PackageInfo packageInfo = installedPackages.get(i);
            arrayList.add(new AppBean(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString(), packageInfo.packageName, packageInfo.versionName, packageInfo.versionCode, packageInfo.applicationInfo.loadIcon(context.getPackageManager())));
        }
        return arrayList;
    }

    public static String findApp(Context context, String str) {
        try {
            return context.getPackageManager().getApplicationInfo(str, 0).loadLabel(context.getPackageManager()).toString();
        } catch (Exception e) {
            e.printStackTrace();
            return context.getString(R.string.not_find);
        }
    }
}
